cmake_minimum_required(VERSION 3.18)

project(FuncDemo)

# 实现一个加法函数，演示如何传递结果到外层作用域
function(sum A B)
    math(EXPR RESULT "${A} + ${B}")
    set(LOCAL_SUM ${RESULT})                        # 局部变量
    set(OUTPUT_SUM ${RESULT} PARENT_SCOPE)          # 父级作用域变量
    set(CACHE_SUM ${RESULT} CACHE STRING "sum")     # 缓存变量
endfunction(sum A B)

sum(3 5)

message(STATUS "LOCAL_SUM = ${LOCAL_SUM}")
message(STATUS "OUTPUT_SUM = ${OUTPUT_SUM}")
message(STATUS "CACHE_SUM = $CACHE{CACHE_SUM}")